<template>
  <d2-container>
    <div class="flex-1 mt-2 ml-2">
      <el-table :data="forumreplyList" border stripe>
        <el-table-column align="center" label="序号" type="index" width="45" />
        <el-table-column align="center" label="帖子标题" prop="post_title" width="130" />
        <el-table-column align="center" label="评论内容" prop="reply_content" width="230" />
        <el-table-column align="center" label="评论时间" prop="create_time" width="70" />
        <el-table-column align="center" label="操作" width="80">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex-1 mt-3">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page.sync="queryInfo.page" layout="total, prev, pager, next" :total="forumreplyTotal">
        </el-pagination>
      </div>
    </div>
  </d2-container>
</template>

<script>
  import {
    forumreplyListUrl,
    forumreplyDeleteUrl
  } from "@/utils/forum"
  export default {
    data() {
      return {
        queryInfo: {
          page: 1,
          page_size: 10
        },
        forumreplyList: [],
        forumreplyTotal: 1
      }
    },
    created() {
      this.getForumreplyList()
    },
    methods: {
      getForumreplyList() {
        this.$get(forumreplyListUrl, this.queryInfo).then(res => {
          if (res.data.code == 200) {
            this.forumreplyList = res.data.data.list
            this.forumreplyTotal = res.data.data.total
          }
        })
      },
      // 分页页码显示条数
      handleSizeChange(newSize) {
        // 把每页显示多少数据重新赋值
        this.queryInfo.page_size = newSize
        this.getForumreplyList()
      },
      // 翻页事件
      handleCurrentChange(newPage) {
        this.queryInfo.page = newPage
        this.getForumreplyList()
      },
      handleDelete(replyId) {
        this.$confirm('此操作将永久删除该分类, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$del(forumreplyDeleteUrl + replyId + '/').then(res => {
            if (res.data.code == 200) {
              this.getForumreplyList()
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
    }
  }
</script>

<style>
</style>
